var e = require("../../@babel/runtime/helpers/toConsumableArray"),
  t = require("../../utils/http.js"),
  r = (require("../../utils/api.js"), require("../../utils/weapp-qrcode.js")),
  i = require("../../utils/language/switchLanguage.js"),
  a = !1;
Page({
  data: {
    isDown: !1,
    isShowQr: !1,
    returnList: [],
    electronicTickets: [],
    code_i: 0,
    code_j: 0,
    current: 0,
    isShowQrcode: 0,
    qrcodeMaxAge: 16,
    qrcodeMinAge: 0,
    newOrderDetailInfoVOList: [],
  },
  onLoad: function (e) {
    this.initLanguage(),
      this.setData({ orderNo: e.orderNo }),
      this.getOrderDetail({ orderSn: e.orderNo }),
      this.getCustomerUserList({ orderSn: e.orderNo }),
      this.getUniversalTicketConfig();
  },
  initLanguage: function () {
    var e = i.languageVersion(wx.getStorageSync("language"));
    this.setData({ _t: e, languageType: wx.getStorageSync("language") });
  },
  getUniversalTicketConfig: function () {
    var e = this;
    t.getUniversalTicketConfig().then(function (t) {
      e.setData({
        isShowQrcode: t.data.isShowQrcode,
        qrcodeMaxAge: t.data.qrcodeMaxAge,
        qrcodeMinAge: t.data.qrcodeMinAge,
      });
    });
  },
  hideID: function (e) {
    if ("string" == typeof e && e.length >= 15) {
      var t = e.length - 8,
        r = "*".repeat(t);
      return e.substr(0, 4) + r + e.substr(-4);
    }
    return "**********";
  },
  toPage: function (e) {
    wx.navigateTo({
      url:
        "plugin-private://wx393d60d93f70599c/pages/Rule/index?orderType=" +
        this.data.content.orderType +
        "&teamType=" +
        this.data.content.teamType,
    });
  },
  getOrderDetail: function (r) {
    var i = this,
      a = this;
    t.getOrderDetail(r).then(function (t) {
      var r = t.data;
      if (
        (i.setData({ content: r }), 3 != r.orderStatus && 4 != r.orderStatus)
      ) {
        var n = [],
          o = [];
        r.orderDetailInfoVOList &&
          r.orderDetailInfoVOList.map(function (t) {
            t.museumOrderUserVOS && o.push.apply(o, e(t.museumOrderUserVOS));
          }),
          o.forEach(function (e) {
            e.customerIdCard = a.hideID(e.customerIdCard);
          }),
          i.setData({ newOrderDetailInfoVOList: o });
        for (var s = 0; s < r.orderDetailInfoVOList.length; s++)
          for (
            var c = 0;
            c < r.orderDetailInfoVOList[s].museumOrderUserVOS.length;
            c++
          ) {
            i.makeCode(
              r.orderDetailInfoVOList[s].museumOrderUserVOS[c].electronicTicket,
              s,
              c,
              !1,
            );
            var d = {};
            (d.idx = s), (d.idy = c), n.push(d);
          }
        i.setData({ electronicTickets: n });
      }
    });
  },
  getEle: function (e) {
    var r = this,
      i = this.data.code_i,
      a = this.data.code_j,
      n = {
        electronicTicket:
          this.data.content.orderDetailInfoVOList[i].museumOrderUserVOS[a]
            .electronicTicket,
      };
    t.getEle(n).then(function (e) {
      r.makeCode(e.data.electronicTicket, i, a, !0);
    });
  },
  makeCode: function (e, t, i, a) {
    a && wx.showLoading({ title: "" });
    var n = (200 * wx.getSystemInfoSync().windowWidth) / 375,
      o = n,
      s = this,
      c = this.data.content;
    (c.orderDetailInfoVOList[t].museumOrderUserVOS[i].codeUrl = ""),
      new r("myQrcode", {
        text: e,
        width: n,
        height: o,
        colorDark: "#181818",
        colorLight: "white",
        correctLevel: r.CorrectLevel.H,
        callback: function (e) {
          a && wx.hideLoading(),
            (c.orderDetailInfoVOList[t].museumOrderUserVOS[i].codeUrl = e.path),
            s.setData({ content: c }),
            wx.hideLoading();
        },
      });
  },
  changeQR: function (e) {
    var r = this;
    if (!a) {
      a = !0;
      var i = e.detail.current,
        n = this.data.electronicTickets[i],
        o = e.detail.show,
        s = e.currentTarget.dataset.show;
      if (o || s) {
        (a = !1), this.setData({ code_i: n.idx, code_j: n.idy, currentQR: i });
        var c = {
          electronicTicket:
            this.data.content.orderDetailInfoVOList[n.idx].museumOrderUserVOS[
              n.idy
            ].electronicTicket,
        };
        1 == this.data.isShowQrcode
          ? t.getEle(c).then(function (e) {
              r.makeCode(e.data.electronicTicket, n.idx, n.idy, !1), (a = !1);
            })
          : setTimeout(function () {
              a = !1;
            }, 500);
      } else a = !1;
    }
  },
  changeArrow: function (e) {
    var t = e.currentTarget;
    t.disabled = !0;
    var r = e.currentTarget.dataset.type,
      i = this.data.current;
    "left" == r &&
      i - 1 >= 0 &&
      (this.setData({ current: i - 1 }),
      this.changeQR({ detail: { current: i, show: !1 } })),
      "right" == r &&
        this.data.electronicTickets.length > i + 1 &&
        (this.setData({ current: i + 1 }),
        this.changeQR({ detail: { current: i, show: !1 } })),
      setTimeout(function () {
        t.disabled = !1;
      }, 500);
  },
  getCustomerUserList: function (e) {
    var r = this;
    t.getCustomerUserList(e).then(function (e) {
      r.setData({ returnList: e.data.refueList });
    });
  },
  CancelOrder: function () {
    wx.navigateTo({
      url: "plugin-private://wx393d60d93f70599c/pages/teamCancel-order/index?orderSn=".concat(
        this.data.content.orderSn,
      ),
    });
  },
  Expand: function () {
    this.setData({ isDown: !this.data.isDown });
  },
  expandMore: function () {
    var e = this;
    if ((this.setData({ isShowQr: !this.data.isShowQr }), this.data.isShowQr)) {
      var r = this.data.code_i,
        i = this.data.code_j,
        a = {
          electronicTicket:
            this.data.content.orderDetailInfoVOList[r].museumOrderUserVOS[i]
              .electronicTicket,
        };
      1 == this.data.isShowQrcode &&
        t.getEle(a).then(function (t) {
          e.makeCode(t.data.electronicTicket, r, i, !0);
        });
    }
  },
  CallPhone: function () {
    wx.makePhoneCall({ phoneNumber: wx.getStorageSync("telphoneNumber") });
  },
  onReady: function () {},
  onShow: function () {},
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {},
  onReachBottom: function () {},
});
